package simulation;

import edu.cornell.lassp.houle.RngPack.Ranlux;

/**
 * @author  user
 */
public abstract class ItemStepDistribution {
	/**
	 * @uml.property  name="cdf"
	 * @uml.associationEnd  
	 */
	private CumulativeDistributionFunction cdf;
	
	public ItemStepDistribution() {

	}

	public abstract void getDistributionFunction(int itemId);
	
	public int nextItem() {
		Ranlux random = new Ranlux(System.currentTimeMillis());
		//uniformly distributed between 0 and 1
		double randomDouble = random.raw();
		int newItemPosition = 0;
		for (int i = 0; i < getCdf().getItemIds().size(); i++) {
			if (getCdf().getItemThresholds().get(i) > randomDouble) {
				newItemPosition = i;
				break;
			}
		}
		return newItemPosition;
	}

	/**
	 * @param cdf  the cdf to set
	 * @uml.property  name="cdf"
	 */
	public void setCdf(CumulativeDistributionFunction cdf) {
		this.cdf = cdf;
	}

	/**
	 * @return  the cdf
	 * @uml.property  name="cdf"
	 */
	public CumulativeDistributionFunction getCdf() {
		return cdf;
	}
}
